<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{ item }}</li>
  </ul>
  <ul>
    <li v-for="p in productArr"></li>
  </ul>
  <table border="1px"></table>
  <tr>
    <th>商品编号</th>
    <th>商品标题</th>
    <th>商品价格</th>
    <th>商品库存</th>
    <th>操作</th>
  </tr>
  <tr v-for="(item,index) in productArr">
    <td>{{index+1}}</td>
    <td>{{item.title}}</td>
    <td>{{item.price}}</td>
    <td>{{item.count}}</td>
    <td>
      <button @click="del(index)">删除</button>
    </td>
  </tr>
</template>

<script setup>
import {ref} from "vue";

const productArr = ref([
  {title: '奔驰', price: '5000000', count: '10'},
  {title: ' Audi', price: '4000000', count: '10'},
  {title: 'BMW', price: '3000000', count: '10'},
  {title: 'Jeep', price: '2000000', count: '10'},
  {title: 'Tesla', price: '1000000', count: '10'},
  {title: 'Ferrari', price: '500000', count: '10'},
])
const del=(index)=>{
  if (confirm('确定删除吗？')){
    productArr.value.splice(index,1)
  }
}
</script>

<style scoped>

</style>